package com.library.controller;



import com.library.domain.Author;
import com.library.mapper.AuthorMapper;
import com.library.service.AuthorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/lib/author")
public class AuthorController {
    private String prefix = "system/library/author";

    @Autowired
    AuthorService authorService;

    @Autowired
    AuthorMapper authorMapper;



    @GetMapping()
    public String pub(){
        return prefix+"/author";
    }
    @GetMapping("/selectAll")
    public List<Author> selectAll() {

        return authorService.selectAll();
    }

    @GetMapping("/aus")
    public List<String> selectAus(){
        return authorMapper.selectAuthors();
    }

    @GetMapping("/key/{key}")
    public List<Author> selectKey(@PathVariable String key){
        return authorMapper.selectKey(key);
    }
    @PostMapping("/add")
    public Integer add(@RequestBody Author author) {
        return authorService.add(author);
    }

    @DeleteMapping("/del/{aid}")
    public Integer del(@PathVariable int aid) {
        return authorService.del(aid);
    }
    @CrossOrigin
    @PostMapping("/change")
    public Integer change(@RequestBody Author author) {
        return authorService.change(author);
    }

}
